<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>被测人管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>

<script type="text/javascript">
	$(function() {

		main();

	});

	function main() {

		getContractPinlei();
		initValidate();

	}

	function initValidate() {
		$.extend($.fn.validatebox.defaults.rules, {

			indexrange : {
				validator : function(value) {
					var reg = /^\+?[1-9][0-9]*-\+?[1-9][0-9]*$/;
					return reg.test(value);
				},
				message : '请输入正确格式，例如“1-100”'
			}

		})
	}

	window.dataArray = new Array();
	function getContractPinlei() {
		window.pcode = GetQueryString('pcode');

		//发送网络请求
		$
				.get(
						"${pageContext.request.contextPath}/clothesType/page.findByTypeCPIDSerial.ashx?typeCPIDSerial="
								+ window.pcode,
						function(result) {

							for (var i = 0; i < result.length; i++) {

								var pinleiming = result[i].typeName;
								var celiangbuweiNameStr = result[i].typeItemsName;
								var celiangbuweiNameArr = celiangbuweiNameStr
										.split(',');

								for (var int2 = 0; int2 < celiangbuweiNameArr.length; int2++) {
									var celaingbuwei = new Object();
									celaingbuwei.field = pinleiming + '_'
											+ celiangbuweiNameArr[int2];
									celaingbuwei.title = celiangbuweiNameArr[int2];
									celaingbuwei.rowspan = 1;
									window.dataArray.push(celaingbuwei);
								}

								var autoCoatSize = new Object();
								autoCoatSize.field = pinleiming + '_自动上衣号型';
								autoCoatSize.title = '自动上衣号型';
								autoCoatSize.rowspan = 1;
								window.dataArray.push(autoCoatSize);

								var autoTrouserSize = new Object();
								autoTrouserSize.field = pinleiming + '_自动下裤号型';
								autoTrouserSize.title = '自动下裤号型';
								autoTrouserSize.rowspan = 1;
								window.dataArray.push(autoTrouserSize);

								var manualCoatSize = new Object();
								manualCoatSize.field = pinleiming + '_人工上衣号型';
								manualCoatSize.title = '人工上衣号型';
								manualCoatSize.rowspan = 1;
								window.dataArray.push(manualCoatSize);

								var manualTrouserSize = new Object();
								manualTrouserSize.field = pinleiming
										+ '_人工下裤号型';
								manualTrouserSize.title = '人工下裤号型';
								manualTrouserSize.rowspan = 1;
								window.dataArray.push(manualTrouserSize);

								var style = new Object();
								style.field = pinleiming + '_穿衣风格';
								style.title = '穿衣风格';
								style.rowspan = 1;
								window.dataArray.push(style);

								var beizhu = new Object();
								beizhu.field = pinleiming + '_备注';
								beizhu.title = '备注';
								beizhu.rowspan = 1;
								window.dataArray.push(beizhu);

								var kuanshi = new Object();
								kuanshi.field = pinleiming + '_可选款式';
								kuanshi.title = '款式';
								kuanshi.rowspan = 3;
								window.dataArray.push(kuanshi);

								var pinlei = new Object();
								pinlei.title = pinleiming;
								pinlei.align = 'center';
								pinlei.colspan = celiangbuweiNameArr.length + 6;
								window.userArray.push(pinlei)

							}

							initDatagrid();
							initBtn();

						});

	}

	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}

	function initDatagrid() {
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({
			visibility : "visible"
		});

		// 收派标准数据表格
		$('#grid')
				.datagrid(
						{
							iconCls : 'icon-forward',
							fit : true,
							border : false,

							striped : true,
							toolbar : '#tb',
							url : "${pageContext.request.contextPath}/customer/page.listByHTSerial.ashx",
							queryParams : window.pcode != null ? {
								'hetongSerial' : window.pcode
							} : new Object(),

							idField : 'customerID',
							columns : columns,
							pageList : [ 5, 10, 50, 100 ],
							pagination : true,
							view : myview,
							emptyMsg : "<font size=5>暂无记录</font>"

						});
	}

	function initBtn() {

		$('#search').click(doSearch);
		$('#export').click(doExport);
		$('#exportDone').click(doExportDone);
		$('#exportDoing').click(doExportDoing);
		$('#exportChecked').click(doExportChecked);
		$('#exportAllClothes').click(doExportAllClothes);
		$('#exportAllBody').click(doExportAllBody);
		$('#editData').click(doEditData);

		initTaskAreaCombobox();
	}

	function initTaskAreaCombobox() {
		$
				.get(
						"${pageContext.request.contextPath}/linkman/page.everyone.findAllByContractSerial.ashx?lMIDContract="
								+ window.pcode, function(data) {

							var defaultAll = new Object();
							defaultAll.lMCom = "全部";
							defaultAll.lMIDFenChang = '';
							defaultAll.selected = true;
							data.unshift(defaultAll);

							$('#sc_linkmanName').combobox({
								valueField : 'lMIDFenChang',
								textField : 'lMCom',
								data : data,
								editable : false
							});

						});

	}

	function doEditData() {
		var checkedItems = $('#grid').datagrid('getChecked');
		if (checkedItems.length == 0) {
			$.messager.alert("提示", "您没有选择任何数据", 'info');
			return;
		} else if (checkedItems.length > 1) {
			$.messager.alert("提示", "每次只能编辑一条数据 ", 'info');
			return;
		} else {
			location.href = "${pageContext.request.contextPath}/customer/page.editData.ashx?customerID="
					+ checkedItems[0].customerID
					+ "&hetongSerial="
					+ window.pcode;
		}

	}

	function doExportAllBody() {

		var paramStr = "";

		var queryVar = getQueryParams(new Object());
		for ( var key in queryVar) {//遍历json对象的每个key/value对,p为key
			//alert(key + " " + queryVar[p]);

			if (queryVar[key] != null && queryVar[key] != undefined
					&& queryVar[key] != '') {
				paramStr += "&" + key + "="
						+ encodeURI(encodeURI(queryVar[key]));
			}

		}

		location.href = "${pageContext.request.contextPath}/langdeng/page.langdeng.hodo_exportdata_body.ashx?hetongSerial="
				+ window.pcode + paramStr;
	}

	function doExportAllClothes() {

		var paramStr = "";

		var queryVar = getQueryParams(new Object());
		for ( var key in queryVar) {//遍历json对象的每个key/value对,p为key
			//alert(key + " " + queryVar[p]);

			if (queryVar[key] != null && queryVar[key] != undefined
					&& queryVar[key] != '') {
				paramStr += "&" + key + "="
						+ encodeURI(encodeURI(queryVar[key]));
			}

		}

		location.href = "${pageContext.request.contextPath}/customer/page.everyone.hodo_exportdata_clothes.ashx?hetongSerial="
				+ window.pcode + paramStr;
	}

	function doExport() {

		location.href = "${pageContext.request.contextPath}/customer/page.hodo_exportdata.ashx?hetongSerial="
				+ window.pcode;
	}

	function doExportDone() {

		location.href = "${pageContext.request.contextPath}/customer/page.hodo_exportdata.ashx?cMeasureState=is_1&hetongSerial="
				+ window.pcode;
	}

	function doExportDoing() {

		location.href = "${pageContext.request.contextPath}/customer/page.hodo_exportdata.ashx?cMeasureState=is_null&hetongSerial="
				+ window.pcode;
	}

	function doExportChecked() {

		var checkedItems = $('#grid').datagrid('getChecked');
		if (checkedItems.length == 0) {
			$.messager.alert("提示", "您没有选择任何数据", 'info');
			return;
		}
		var ids = '';
		var stopFlag = 0;
		$.each(checkedItems, function(index, item) {
			/* if(item.exportstatus==1){
				  $.get("page.staffGet.ashx?sId="+item.exporterID, function(result){
					  $.messager.alert("提示", "【"+item.customerName+"】"+'已经导出去了。<br/><br/>导出人：'+result+'<br/><br/>导出时间：'+formatterDate(item.exportTime), 'info');
					});
				
				stopFlag = 1;
				return;
			} */

			if (index == 0) {
				ids = ids + item.customerID;
			} else {
				ids = ids + ',' + item.customerID;
			}
		});

		if (stopFlag == 1) {
			return;
		} else {
			location.href = "${pageContext.request.contextPath}/customer/page.hodo_exportCheckedData.ashx?ids="
					+ ids + "&hetongSerial=" + window.pcode;

		}

	}

	function getQueryParams(queryParams) {
		var searchcontent = $('#searchcontent').val();
		var searchcontent_creator = $('#searchcontent_creator').val();
		var v_fenchang = $('#sc_linkmanName').combobox('getValue');
		var cMeasureState = $('#sc_measureStatus').combobox('getValue');
		var exportStatus = $('#sc_exportStatus').combobox('getValue');
		var indexRange = $('#sc_indexrange').val();
		queryParams.customerName = searchcontent;
		queryParams.v_creatorName = searchcontent_creator;
		queryParams.v_fenchang = v_fenchang;
		queryParams.cMeasureState = cMeasureState;
		queryParams.exportstatus = exportStatus;

		if (indexRange.split("-").length > 0) {
			queryParams.start_index = indexRange.split("-")[0];
			queryParams.end_index = indexRange.split("-")[1];

		}
		return queryParams;

	}

	//增加查询参数，重新加载表格  
	function reloadgrid() {

		//查询参数直接添加在queryParams中      
		var queryParams = $('#grid').datagrid('options').queryParams;
		getQueryParams(queryParams);
		$('#grid').datagrid('options').queryParams = queryParams;
		$("#grid").datagrid('load');
	}

	function doSearch() {
		reloadgrid();
	}

	/* 二维数组操作 
	var a = [1,2,3,4]; 
	a.push(9)
	var b = [5,6,7,8];
	var c = new Array(a,b);  
	
	alert(c[1][1]) */

	window.userArray = [ /* {
	       field : 'ck',
	       checkbox : true,
	       rowspan:2
	   }, */{
		field : 'customerIndex',
		title : '编号',
		width : 60,
		rowspan : 2

	}, {
		field : 'customerName',
		title : '姓名',
		width : 100,
		rowspan : 2
	}, {
		field : 'customerSex',
		title : '性别',
		width : 30,
		rowspan : 2,
		formatter : formatterSex

	}, {
		field : 'customerAge',
		title : '年龄',
		width : 30,
		rowspan : 2
	}, {
		field : 'customerTel',
		title : '电话',
		width : 100,
		rowspan : 2
	}, {
		field : 'customerCom',
		title : '单位',
		width : 150,
		rowspan : 2

	}, {
		field : 'customerDep',
		title : '部门',
		width : 60,
		rowspan : 2
	},{
		field : 'customerChildDep',
		title : '分部门',
		width : 60,
		rowspan : 2
	}, {
		field : 'customerGroup',
		title : '班组',
		width : 60,
		rowspan : 2
	}, {
		field : 'customerPost',
		title : '岗位',
		width : 60,
		rowspan : 2
	}, {
		field : 'customerDuty',
		title : '职务',
		width : 60,
		rowspan : 2
	}, {
		field : 'customerBeiZhu',
		title : '备注',
		width : 100,
		rowspan : 2
	}, {
		field : 'v_fenchang',
		title : '分场',
		width : 140,
		rowspan : 2
	}, {
		field : 'v_creatorName',
		title : '创建人',
		width : 100,
		rowspan : 2
	}, {
		field : 'createTime',
		title : '创建时间',
		width : 100,
		rowspan : 2,
		formatter : formatterDate
	}, {
		field : 'exportstatus',
		title : '导出状态',
		width : 60,
		rowspan : 2,
		formatter : formatterExportstatus
	}, {
		field : 'customerClothLike',
		title : '衣着偏好',
		width : 100,
		rowspan : 2
	}, {
		field : 'customerBodyType',
		title : '体型特点',
		width : 100,
		rowspan : 2
	}, {
		field : 'cMeasureState',
		title : '量体状态',
		width : 40,
		rowspan : 2,
		formatter : formatterMeasureState
	}, {
		field : 'cUploadState',
		title : '上传状态',
		width : 40,
		rowspan : 2,
		formatter : formatterUploadState
	}, {
		field : 'v_uploaderName',
		title : '上传人',
		width : 40,
		rowspan : 2,

	}, {
		field : 'cPhotoZM',
		title : '正面照',
		width : 40,
		rowspan : 2,
		formatter : formattercPhoto

	}, {
		field : 'cPhotoCM',
		title : '侧面照',
		width : 40,
		rowspan : 2,
		formatter : formattercPhoto

	}, {
		field : 'cPhotoBM',
		title : '背面照',
		width : 40,
		rowspan : 2,
		formatter : formattercPhoto

	}, {
		field : 'cPhotoQM',
		title : '签名照',
		width : 40,
		rowspan : 2,
		formatter : formattercPhoto

	} ]

	function formattercPhoto(value, row, index) {

		if (value) {
			return '<a href='+value+'   target="_blank">查看</a>'
		} else {
			return "无";
		}
	}

	var columns = new Array(window.userArray, window.dataArray);

	function formatterUploadState(value, row, index) {
		if (value == 1) {
			return "已上传";
		} else {
			return "未上传";
		}
	}

	function formatterExportstatus(value, row, index) {
		if (value == 1) {
			return "<font color='red'>已导出</font >";
		} else {
			return "未导出";
		}
	}
	function formatterId(value, row, index) {
		return "<a onclick=showDetails(" + index + ") href=#>详情</a>";
	}
	function showDetails(index) {
		$('#grid').datagrid('selectRow', index);// 关键在这里  
		var row = $('#grid').datagrid('getSelected');
		if (row) {
			location.href = "${pageContext.request.contextPath}/page.customerdetails.ashx?id="
					+ row.id;

		}
	}

	function formatterDate(value) {
		if (value == '' || null == value) {
			return '';
		}
		var now = new Date(value);
		var now = new Date(now.valueOf() - 1000 * 60 * 60 * 14);

		var year = now.getYear() + 1900;
		var month = now.getMonth() + 1;
		var date = now.getDate();
		var hour = now.getHours();
		var minute = now.getMinutes();
		minute = (minute > 9) ? minute = minute : minute = '0' + minute;
		//var second=now.getSeconds(); 
		return year + "-" + month + "-" + date + " " + hour + ":" + minute;
	}

	function doFuQuan(index) {
		$('#grid').datagrid('selectRow', index);// 关键在这里  
		var row = $('#grid').datagrid('getSelected');

		if (row) {
			$.messager.alert("提示", "正在完善...", 'info');
		}
	}

	function formatterMeasureState(value, row, index) {
		if (value == '1') {
			return "已量";
		} else {
			return "未量";
		}
	}

	function formatterSex(value, row, index) {
		if (row.customerSex == 0) {
			return "男";
		} else if (row.customerSex == 1) {
			return "女";
		}
	}

	var myview = $.extend({}, $.fn.datagrid.defaults.view, {
		onAfterRender : function(target) {
			$.fn.datagrid.defaults.view.onAfterRender.call(this, target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children(
					'div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length) {
				var d = $('<div class="datagrid-empty"></div>').html(
						opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position : 'absolute',
					left : 0,
					top : 50,
					width : '100%',
					textAlign : 'center'
				});
			}
		}
	});
</script>
</head>
<body class="easyui-layout">
	<div region="center">
		<table id="grid"></table>
	</div>

	<div id="tb" style="padding: 5px; height: auto">
		<div style="margin-bottom: 5px">

			编号范围: <input id="sc_indexrange" class="easyui-validatebox"
				requird="false" validtype="indexrange" style="width: 100px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名: <input
				id="searchcontent" class="easyui-textbox" style="width: 100px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分场: <input
				id="sc_linkmanName" class="easyui-combobox" style="width: 100px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建人: <input
				id="searchcontent_creator" class="easyui-textbox"
				style="width: 100px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;导出状态: <select
				id="sc_exportStatus" class="easyui-combobox" style="width: 100px">
				<option value="2">全部</option>
				<option value="1">已导出</option>
				<option value="0">未导出</option>
			</select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量体状态: <select
				id="sc_measureStatus" class="easyui-combobox" style="width: 100px">
				<option value="all">全部</option>
				<option value="is_1">已量</option>
				<option value="is_null">未量</option>
			</select>




			<!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目代号: <input id="pcode"  class="easyui-textbox" style="width:200px">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
			<a href="#" id="search" class="easyui-linkbutton"
				iconCls="icon-search">搜索</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!--   <a href="#"  id="export" class="easyui-linkbutton" iconCls="icon-save">导出全部</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 <a href="#"  id="exportDone" class="easyui-linkbutton" iconCls="icon-save">导出已量</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 <a href="#"  id="exportDoing" class="easyui-linkbutton" iconCls="icon-save">导出未量</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 <a href="#"  id="exportChecked" class="easyui-linkbutton" iconCls="icon-save">导出选中</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
			<a href="#" id="editData" class="easyui-linkbutton"
				iconCls="icon-edit">编辑数据</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!--    <a href="#"  id="exportAllBody" class="easyui-linkbutton" iconCls="icon-save">导出搜索结果净体数据</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 <a href="#"  id="exportAllClothes" class="easyui-linkbutton" iconCls="icon-save">导出搜索结果成衣数据</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			  -->
			<a href="#" id="exportAllBody" class="easyui-linkbutton"
				iconCls="icon-save">导出搜索结果量体数据</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</div>
	</div>



</body>
</html>